class EventBus {
	constructor() {
		this.subscription = []
	}
	on(key, f) {
		for(let i = 0; i < this.subscription.length; i++){
			if(key === this.subscription[i].key){
				return
			}
		}
		this.subscription.push({
			key,
			f
		})
	}
	emit(key, value) {
		for(let i = 0; i < this.subscription.length; i++){
			if(key === this.subscription[i].key){
				this.subscription[i].f(value)
				return
			}
		}
	}
	off(key) {
		for(let i = 0; i < this.subscription.length; i++){
			if(key === this.subscription[i].key){
				this.subscription.splice(i, 1)
				return
			}
		}
	}
}

export default new EventBus()